#!/bin/bash
# 一键构建所有格式的安装包

set -e

echo "=========================================="
echo "  Notepad-- 多格式打包脚本"
echo "=========================================="
echo ""

# 进入构建目录
cd how_build
mkdir -p build
cd build

# 清理之前的构建
rm -rf *

# CMake 配置
echo "[1/4] CMake 配置..."
cmake ..

# 编译
echo ""
echo "[2/4] 编译项目..."
make -j$(nproc)

# 打包 DEB
echo ""
echo "[3/4] 生成 DEB 包 (Debian/Ubuntu)..."
cpack -G DEB

# 打包 RPM
echo ""
echo "[4/4] 生成 RPM 包 (Fedora/RHEL/openSUSE)..."
if command -v rpmbuild &> /dev/null; then
    cpack -G RPM
else
    echo "  ⚠ 跳过 RPM 打包（未安装 rpmbuild）"
fi

# 打包 TGZ
echo ""
echo "生成 TGZ 包 (通用)..."
cpack -G TGZ

echo ""
echo "=========================================="
echo "  打包完成！"
echo "=========================================="
echo ""
echo "生成的文件："
ls -lh *.deb *.rpm *.tar.gz 2>/dev/null || ls -lh notepad--*
echo ""
echo "安装方式："
echo "  DEB: sudo dpkg -i notepad--_1.23.0_amd64.deb"
echo "  RPM: sudo rpm -ivh notepad--1.23.0-1.x86_64.rpm"
echo "  TGZ: tar xzf notepad--1.23.0-Linux.tar.gz"
echo ""

